 <!-- 病虫害防治 -->
<template>
  <BaseMainSlot>
    <template v-slot:btn-box>
      <ActionBar
        :page-no="29"
        :add-active="addActive"
        :del-active="delActive"
        :has-edit="false"
        :has-cancel="false"
        :has-edit-column="true"
        :has-export="searchlist.result == 1"
        @showColumn="showColumn"
        @download="download"
        @add="add"
        @del="delList"
      />
    </template>
    <template v-slot:search-box>
      <SearchForm
        :formConfig="formConfig"
        :formData="searchlist"
        @search="search"
      ></SearchForm>
    </template>
    <template v-slot:table-box>
      <Table
        @sortChange="changeTableSort"
        :propList="tableColumn"
        v-loading="loading"
        :listData="tableData"
        :showSelectColumn="true"
        @handleSelectionChange="handleSelectionChange"
      >
        <!-- 批次名称 -->
        <template v-slot:batchName="{ row }">
          <template v-if="row.batchNo">
            <template
              v-if="batchList.filter((el) => el.batchNo === row.batchNo)[0]"
            >
              {{
                batchList.filter((el) => el.batchNo === row.batchNo)[0]
                  .batchName
              }}</template
            >
          </template>
        </template>
        <!-- 时间 -->
        <template v-slot:disposeDate="{ row }">
          <template v-if="row.batchNo">
            {{ row.disposeDate }}
          </template>
        </template>
        <!-- 查看设施  -->
        <template v-slot:facilityNoList="{ row }">
          <template v-if="row.batchNo">
            <el-button
              class="text-btn-cursor"
              type="text"
              size="small"
              @click="checkFacility(row)"
            >
              <i class="el-icon-view"></i> 查看
            </el-button>
          </template>
        </template>
        <!-- 查看用药信息 -->
        <template v-slot:useMedicine="{ row }">
          <template v-if="row.batchNo">
            <el-button
              class="text-btn-cursor"
              type="text"
              size="small"
              @click="useMedicine(row)"
            >
              <i class="el-icon-view"></i> 查看
            </el-button>
          </template>
        </template>
        <!-- 操作 -->
        <template v-slot:operation="{ row }">
          <template v-if="row.batchNo">
            <el-button
              class="text-btn-cursor"
              type="text"
              size="small"
              @click="handle(row)"
            >
              处 理
            </el-button>
            <el-button
              v-if="row.batchNo"
              class="text-btn-cursor cursor-delete"
              type="text"
              size="small"
              @click="delSingle(row)"
            >
              <i class="el-icon-delete"></i> 删除
            </el-button>
          </template>
        </template>
      </Table>
      <Pagination
        :page-size="pageSize"
        :current-page="currentPage"
        :total-size="totalSize"
        @changePageSize="changePageSize"
        @changeCurrentPage="changeCurrentPage"
      />
    </template>
    <template v-slot:dialog>
      <!-- 处理 -->
      <el-dialog
        title="处理病虫害"
        :visible.sync="dialogFormVisible"
        width="55%"
        @close="cancel"
      >
        <el-form
          ref="handlerFormData"
          label-position="left"
          :model="handlerFormData"
          :rules="rules"
          class="el-form"
        >
          <el-form-item label="处理图片：" class="w50p">
            <ele-upload-image
              v-model="image2"
              :response-fn="handleResponse2"
              :before-remove="handleRemove2"
              :headers="headers"
              :file-size="10"
              :action="ImageUrl()"
            />
          </el-form-item>
          <el-form-item label="处理日期：" prop="disposeDate" class="w50p">
            <el-date-picker
              v-model="handlerFormData.disposeDate"
              type="datetime"
              value-format="timestamp"
              clearable
            />
          </el-form-item>
          <el-form-item label="备注: " prop="remark" class="w50p">
            <el-input v-model="handlerFormData.remark" clearable />
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button class="zh-button-one" @click="cancel">取 消</el-button>
          <el-button class="zh-button-two" type="primary" @click="handleSave"
            >确 定</el-button
          >
        </span>
      </el-dialog>
      <!-- 添加 -->
      <el-dialog
        :title="`病虫害防治`"
        :visible.sync="isShow"
        @close="addCancel"
      >
        <el-form
          ref="addFormData"
          label-position="left"
          :model="addFormData"
          :rules="rules"
        >
          <el-form-item label="批次名称:" prop="batchNo" class="w50p">
            <el-select
              v-model="addFormData.batchNo"
              clearable
              filterable
              @change="batch"
            >
              <el-option
                v-for="item in batchList"
                :key="item.batchNo"
                :label="item.batchName"
                :value="item.batchNo"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="种植设施:" prop="facilityNoArrays" class="w50p">
            <el-select
              v-model="addFormData.facilityNoArrays"
              multiple
              filterable
              clearable
            >
              <el-option
                v-for="(item, index) in facilityLists"
                :key="index"
                :label="item.facilityName"
                :value="item.facilityNo"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="病虫害类别:" prop="type" class="w50p">
            <el-select v-model="addFormData.type" clearable filterable @change="queryAlarmName">
              <el-option
                v-for="item in alarmTypeList"
                :key="item.name"
                :label="item.name"
                :value="item.name"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="病虫害名称:" prop="name" class="w50p">
            <el-select v-model="addFormData.name" clearable filterable>
              <el-option
                v-for="item in alarmDesList"
                :key="item.alarmTypeNameo"
                :label="item.name"
                :value="item.name"
              />
            </el-select>
          </el-form-item>
          <!-- 药品 -->
          <el-form-item
            v-for="(item, index) in materialNum"
            :key="index"
            style="
              position: relative;
              border: 1px dashed #00ffff;
              padding: 10px;
            "
            class="w100p"
          >
            <el-form-item label="投入药品:" class="w50p">
              <el-select
                v-model="materialNos[index]"
                filterable
                clearable
              >
                <el-option
                  v-for="(item, index) in agriculturalMaterialList"
                  :key="index"
                  :label="item.materialName"
                  :value="item.materialNo"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="投入量:" class="w50p">
              <el-input
                v-model="assetQuantity[index]"
                type="number"
                style="width: 85%;"
                placeholder="请输入投入量"
                clearable
              />
              <div
                style="width: 10%; margin-left: 10px"
                v-if="materialNos[index]"
              >
                {{
                  agriculturalMaterialList.filter(
                    (el) => el.materialNo === materialNos[index]
                  )[0]
                    ? agriculturalMaterialList.filter(
                        (el) => el.materialNo === materialNos[index]
                      )[0].unitName
                    : undefined
                }}
              </div>
            </el-form-item>
            <el-form-item label="换算量:" class="w100p" style="margin-top: 20px">
              <el-input
                v-model="exchangeRatio[index]"
                style="width: 38%"
                type="number"
                placeholder="请输入换算量"
                clearable
              />
              <el-select
                v-model="exchangeUnitNo[index]"
                filterable
                style="width: 38%"
                clearable
              >
                <el-option
                  v-for="item in unitlists"
                  :key="item.unitNo"
                  :label="item.unitName"
                  :value="item.unitNo"
                />
              </el-select>
            </el-form-item>
            <el-form-item
              label="换算预览:"
              class="w100p"
              v-if="
                assetQuantity[index] &&
                exchangeRatio[index] &&
                exchangeUnitNo[index] &&
                materialNos[index]
              "
              style="margin-top: 20px; display: flex"
            >
              <div>
                <span v-if="assetQuantity[index] && exchangeRatio[index]">{{
                  (assetQuantity[index] / exchangeRatio[index]).toFixed(2)
                }}</span>
                <span v-if="materialNos[index] && exchangeUnitNo[index]">{{
                  agriculturalMaterialList.filter(
                    (el) => el.materialNo === materialNos[index]
                  )[0].unitName
                }}</span>
                <span v-if="exchangeUnitNo[index] && materialNos[index]"
                  >/{{
                    unitlists.filter(
                      (el) => el.unitNo === exchangeUnitNo[index]
                    )[0].unitName
                  }}</span
                >
              </div>
              <div v-show="exchangeRatio[index]" style="margin-left: 10px">
                <span v-if="exchangeRatio[index] && exchangeUnitNo[index]"
                  >总计：</span
                >
                <span v-if="exchangeRatio[index]">{{
                  exchangeRatio[index]
                }}</span>
                <span v-if="exchangeUnitNo[index]">
                  {{
                    unitlists.filter(
                      (el) => el.unitNo === exchangeUnitNo[index]
                    )[0].unitName
                  }}</span
                >
              </div>
              <div v-show="assetQuantity[index]" style="margin-left: 10px">
                <span v-if="assetQuantity[index] && materialNos[index]">
                  总重：</span
                >
                <span v-if="assetQuantity[index]">{{
                  assetQuantity[index]
                }}</span>
                <span v-if="materialNos[index]">{{
                  agriculturalMaterialList.filter(
                    (el) => el.materialNo === materialNos[index]
                  )[0].unitName
                }}</span>
              </div>
            </el-form-item>
            <img
                v-show="index === 0"
                src="@/assets/add.png"
                style="
                  position: absolute;
                  right: 0;
                  bottom: 6px;
                  cursor: pointer;
                "
                @click="addMaterial"
              />
              <img src="@/assets/reduce.png" alt="" style="position: absolute;top: 8px; right: 0;cursor: pointer;" v-if="index>0" @click="reduce(index)">
          </el-form-item>
          <el-form-item label="操作人:" prop="disposeManNo" class="w50p">
            <el-select v-model="addFormData.disposeManNo" clearable>
              <el-option
                v-for="(item, index) in staffList"
                :key="index"
                :label="item.person.name"
                :value="item.personNo"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="防治日期:" prop="disposeDate" class="w50p">
            <el-date-picker
              v-model="addFormData.disposeDate"
              type="datetime"
              value-format="timestamp"
              placeholder="请选择通知时间"
            />
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button class="zh-button-one" @click="addCancel">取 消</el-button>
          <el-button class="zh-button-two" type="primary" @click="addSave()"
            >确 定</el-button
          >
        </span>
      </el-dialog>
      <!-- 列配置 -->
      <el-dialog
        id="tableColumnDialog"
        title="配置列"
        :visible.sync="dialogTableColumnVisible"
      >
        <tableColumn
          v-if="dialogTableColumnVisible"
          ref="tableColumn"
          :tableColumn="allTableColumn"
          @cancelColumn="cancelColumn"
        />
        <div slot="footer" class="dialog-footer">
          <el-button
            class="zh-button-one"
            @click="dialogTableColumnVisible = false"
          >
            取 消
          </el-button>
          <el-button class="zh-button-two" type="primary" @click="saveColumn">
            保 存
          </el-button>
        </div>
      </el-dialog>
      <!-- 查看设施 -->
      <el-dialog
        title="设施列表"
        :visible="facilityDialogVisible"
        :before-close="
          () => {
            facilityDialogVisible = false;
          }
        "
      >
        <div class="facility-list">
          <div
            v-for="(item, index) in batchFacilityMapperList"
            :key="index"
            class="facility-item"
          >
            <div class="info-line">
              <div class="name">设施编号：</div>
              <div class="value">{{ item.facilityNo }}</div>
            </div>
            <div class="info-line">
              <div class="name">设施名称：</div>
              <div class="value">{{ item.facilityName }}</div>
            </div>
          </div>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button
            class="zh-button-one"
            @click="facilityDialogVisible = false"
          >
            关 闭
          </el-button>
        </div>
      </el-dialog>
      <!-- 查看用药 -->
      <el-dialog
        title="设施列表"
        :visible="useMedicineVisible"
        :before-close="
          () => {
            useMedicineVisible = false;
          }
        "
      >
        <div class="medicine">
          <div
            v-for="(item, index) in useMedicineList"
            :key="index"
            class="medicine-item"
          >
            <div class="info-line1">
              <div class="name">防治药品名称：</div>
              <div class="value">{{ item.materialDTO.materialName }}</div>
            </div>
            <div class="info-line2">
              <div class="name">投入量：</div>
              <div class="value">{{ item.assetQuantity }}{{ item.materialDTO.unitName }}</div>
            </div>
            <!-- <div class="info-line2">
              <div class="name">药品损耗：</div>
              <div class="value">无</div>
            </div> -->
          </div>
        </div>
        <div slot="footer" class="dialog-footer">
          <el-button class="zh-button-one" @click="useMedicineVisible = false">
            关 闭
          </el-button>
        </div>
      </el-dialog>
    </template>
  </BaseMainSlot>
</template>

<script>
import SearchForm from "@/components/searchForm";
import Table from "@/components/table/table.vue";
import userApi from "@/api/user/index";
import ActionBar from "@/components/ActionBar";
import Pagination from "@/components/Pagination";
import pestInfoApi from "@/api/basic-info-manage/pest-info/index";
import BaseMainSlot from "@/components/BaseMainSlot/newBaseMainSlot.vue";
import { mymixin } from "@/utils/mixins";
import { mapGetters } from "vuex";
import { farmingTypeTitle } from "@/utils/validate";
import baseURL from "@/api/baseURL";
import danwei from "@/api/basic-info-manage/unit-manage/index";
// TODO:
import API from "@/api/digital-production/health-management/pest-control/index";
export default {
  name: "PestRecords",
  components: { SearchForm, Table, ActionBar, Pagination, BaseMainSlot },
  mixins: [mymixin],
  data() {
    var farmingTypeTitles = farmingTypeTitle();
    return {
      materialNum: 1,
      materialNos: [],
      assetQuantity: [],
      exchangeRatio: [],
      exchangeUnitNo: [],
      unitlists: [], //体积单位
      agriculturalMaterialList: [], //药品列表
      staffList: [],
      tableColumn: [
        {
          prop: "batchName",
          label: "批次名称",
          minWidth: "180",
          slotName: "batchName",
        },
        { prop: "batchNo", label: "批次号", minWidth: "120" },
        {
          prop: "facilityNoList",
          label: "防治设施",
          minWidth: "120",
          slotName: "facilityNoList",
        },
        { prop: "type", label: farmingTypeTitles + "类别" },
        { prop: "name", label: farmingTypeTitles + "名称" },
        {
          prop: "useMedicine",
          label: "用药信息",
          minWidth: "120",
          slotName: "useMedicine",
        },
        {
          prop: "disposeDate",
          label: "防治日期",
          slotName: "disposeDate",
          width: "185",
        },
        {
          prop: "operation",
          label: "操作",
          slotName: "operation",
          width: "170",
        },
      ],
      formConfig: [
        {
          label: "批次名称",
          prop: "batchNo",
          type: "select",
          options: [],
          optionKey: { label: "batchName", value: "batchNo" },
        },
        {
          label: "批次号",
          prop: "batchNo",
          type: "select",
          options: [],
          optionKey: { label: "batchNo", value: "batchNo" },
        },
        {
          label: "病虫害类别",
          prop: "alarmType",
          type: "select",
          options: [
            { label: "病害", value: 0 },
            { label: "虫害", value: 1 },
          ],
          optionKey: { label: "label", value: "label" },
        },
        {
          label: "记录日期",
          prop: "date",
          type: "daterange",
        },
      ],
      rules: {
        facilityNoArrays: [
          {
            required: true,
            message: "请选择种植设施",
            trigger: ["change", "blur"],
          },
        ],
        batchNo: [
          {
            required: true,
            message: "请选择批次",
            trigger: ["change", "blur"],
          },
        ],
        type: [
          { required: true, message: "请选择病虫害类别", trigger: "change" },
        ],
        name: [
          { required: true, message: "请选择病虫害名称", trigger: "change" },
        ],
        disposeManNo: [
          {
            required: true,
            message: "作业人不能为空",
            trigger: "change",
          },
        ],
        disposeDate: [
          { required: true, message: "请选择处理日期", trigger: "change" },
        ],
      },
      useMedicineVisible: false, //查看用药
      useMedicineList: [], //用药列表
      isShow: false, //添加dialog
      batchList: [], //批次列表
      facilityLists: [],
      addActive: true,
      facilityDialogVisible: false,
      batchFacilityMapperList: [],
      showpicview: false,
      pictviewurl: "",
      newtotalSize: 0,
      farmingTypeTitles: farmingTypeTitle(),
      // 虫害类别
      alarmTypeList: [
        { name: "病害", value: 0 },
        { name: "虫害", value: 1 },
      ],
      // 当前选中的病虫害图片id
      nowsectpictureid: "",
      isshowhandleview: false,
      alarmDesList: [],
      // 可选择所有地块
      facilityList: [],
      // 所搜索框内容
      searchlist: {
        result: 2,
      },
      pickerOptionsone: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
        shortcuts: [
          {
            text: "今天",
            onClick(picker) {
              picker.$emit("pick", new Date());
            },
          },
          {
            text: "昨天",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24);
              picker.$emit("pick", date);
            },
          },
          {
            text: "一周前",
            onClick(picker) {
              const date = new Date();
              date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", date);
            },
          },
        ],
      },
      // 上传图片
      image2: "",
      imgloading: false,
      addFormData: {
        batchNo: "",
        facilityNoArrays: [],
        type: "",
        name: "",
        disposeManNo: '',
        disposeDate: "",
        inputsRecordBOs: [],
      },
      // 处理
      handlerFormData: {
        disposeDate: "",
        remark: "",
        pictureIdArrays: [],
        batchNo: '',
        facilityNos: '',
        inputsRecordNos: '',
        insectPreventId: '',
        insectPreventNo: '',
        name: '',
        type: ''
      },
      idList: []
    };
  },
  computed: {
    ...mapGetters({
      judgePermission: "permission/judgePermission",
    }),
  },
  watch: {
    dialogFormVisible(v) {
      if (v) {
        this.$nextTick(() => {
          this.$refs.formData?.clearValidate();
        });
      }
    },
  },
  created() {
    this.getfacilityList();
    this.getPestInfo();
    this.getTableDataList();
    this.getSelectDatalist();
  },
  methods: {
    // TODO:获取下拉框数据
    async getSelectDatalist() {
      // 获取所有批次
      API.getAllBatchList({ status: 0, batchType: "BATCH",simpleData: true }).then((res) => {
        this.batchList = res.data;
        this.formConfig[0].options = res.data;
        this.formConfig[1].options = res.data;
      });
      danwei
        .getallunitlist({
          unitTypeNo: "995416607651037184",
          organizationNo: sessionStorage.organizationNo,
        })
        .then((res) => {
          this.unitlists = res.data;
        });
      let medicineList = await API.getMedicineList();
      this.agriculturalMaterialList = medicineList.data;
      API.getEmployeeList().then((res) => {
        if (res.code !== 1) {
          return;
        }
        this.staffList = res.data;
        console.log(this.staffList);
      });
    },
    async batch(e) {
      this.$set(this,'facilityLists',[])
      this.$set(this.addFormData,'facilityNoArrays',[])
      let res = await API.queryFacility(e);
      this.facilityLists = res.data;
    },
    // 查病虫害名称
    async queryAlarmName(e) {
      this.alarmDesList = [];
      this.$set(this.addFormData,'name','')
      let params = {
        alarmTypeName: e,
      };
      let res = await pestInfoApi.queryAlarmName(params);
      this.alarmDesList = res.data;
    },
    // TODO:
    // 图片地址
    ImageUrl() {
      return `${baseURL.webServiceUrl}v3/patrol/picture/addMultipart`;
    },
    //
    handleResponse2(res) {
      this.formData.disposePictureId = res.data;
      pestInfoApi.queryPicture(res.data).then((res) => {
        this.image2 = "data:image/png;base64," + res.data.pictureData;
        if (res.code === 1) {
          this.handlerFormData.pictureIdArrays = [];
          this.handlerFormData.pictureIdArrays.push(res.data.pictureId);
        }
      });
      return this.image2;
    },
    handleRemove2() {
      this.formData.disposePictureId = "";
      this.$set(this.handlerFormData, 'pictureIdArrays', [])
    },
    // 查看设施
    checkFacility(row) {
      let list = [];
      if (row.facilityNos.split(",")) {
        row.facilityNos.split(",").map((el) => {
          let index = this.facilityList.findIndex((ele) => {
            return el === ele.facilityNo;
          });
          list.push({
            facilityNo: el,
            facilityName: this.facilityList[index]?.facilityName || '',
          });
        });
      }
      this.batchFacilityMapperList = list;
      this.facilityDialogVisible = true;
    },
    // 查看用药信息
    useMedicine(row) {
      this.useMedicineList = row.inputsRecordBOs
      this.useMedicineVisible = true;
      console.log(this.useMedicineList);
    },
    // 获取所有设施数据
    getfacilityList() {
      userApi
        .getfacilityAll({
          organizationList: sessionStorage
            .getItem("organizationList")
            .split(","),
          farmingTypeNo: sessionStorage.getItem("farmingTypeNo"),
        })
        .then((res) => {
          this.facilityList = res.data;
        });
    },
    getPestInfo(no) {
      this.$set(this.formData, "alarmDes", "");
      pestInfoApi
        .queryByCondition({
          alarmTypeName: no,
        })
        .then((res) => {
          if (res.code !== 1) return;
          this.alarmDesList = res.data;
        });
    },
    add() {
      this.facilityLists = []
      this.alarmDesList = []
      this.addActive = false;
      this.isShow = true;
      this.addFormData.batchNo = "";
      this.$nextTick(() => {
        this.addFormData = { ...this.addFormData };
        this.$refs.addFormData.resetFields();
      });
    },
    // 添加保存
    addSave() {
      this.$refs.addFormData.validate(async (valid) => {
        if (valid) {
          let params = { ...this.addFormData, farmingTypeNo: sessionStorage.farmingTypeNo };
          params.inputsRecordBOs = [];
          this.materialNos.forEach((el, index) => {
            params.inputsRecordBOs.push({
              assetQuantity: this.assetQuantity[index],
              materialNo: el,
              exchangeRatio: this.exchangeRatio[index],
              exchangeUnitNo: this.exchangeUnitNo[index] || "",
              organizationNo: sessionStorage.getItem("organizationNo"),
            });
          });
          // console.log(params);return;
          let res = await API.add(params);
          if (res.code === 1) {
            this.$message.success("添加成功！");
            this.getTableDataList();
            this.isShow = false;
          } else {
            this.$message.error("添加失败！");
          }
        } else {
          return false;
        }
      });
    },
    addCancel() {
      this.addActive = true;
      this.isShow = false;
      this.materialNos = [];
      this.materialNum = 1;
      this.assetQuantity = [];
      this.exchangeRatio = [];
      this.exchangeUnitNo = [];
      this.addFormData = {};
    },
    // 处理
    async handle(row) {
      if(row.pictureIds) {
        let res = await API.queryPicture(row.pictureIds)
        this.image2 = "data:image/png;base64," + res.data.pictureData
      }
      this.$set(this.handlerFormData,'remark',row.remark)
      this.$set(this.handlerFormData,'disposeDate',new Date(row.disposeDate).getTime())
      this.dialogFormVisible = true;
      this.handlerFormData.batchNo = row.batchNo
      this.handlerFormData.facilityNos = row.facilityNos
      this.handlerFormData.inputsRecordNos = row.inputsRecordNos
      this.handlerFormData.insectPreventId = row.insectPreventId
      this.handlerFormData.insectPreventNo = row.insectPreventNo
      this.handlerFormData.name = row.name
      this.handlerFormData.type = row.type
      this.canInput = true;
      this.addActive = false;
      this.delActive = false;
      this.saveActive = true;
      this.cancelActive = true;
      this.editActive = false;
    },
    // 处理确认
    handleSave() {
      this.$refs.handlerFormData.validate(async (valid) => {
        if (valid) {
          let params = { ...this.handlerFormData };
          let res = await API.edit(params);
          if(res.code===1) {
            this.$message.success('处理成功！')
            this.dialogFormVisible = false
            this.getTableDataList();
          } else {
            this.$message.error('处理失败！')
          }
        } else {
          return false;
        }
      });
    },
    // TODO:表格查询
    getTableDataList() {
      this.loading = true;
      this.tableData = [];
      let params = {
        page: this.currentPage,
        size: this.pageSize,
        sortList: this.sortList || [],
        entity: {
          batchNo: this.searchlist.batchNo || undefined,
          organizationNo: sessionStorage.getItem("organizationNo"),
          type: this.searchlist.alarmType,
        },
      };
      if (this.searchlist.date) {
        params.entity.startTime = new Date(this.searchlist.date[0]);
        params.entity.endTime = new Date(this.searchlist.date[1]);
      }
      this.entity = params.entity;
      API.getList(params).then((res) => {
        if (res.code === 1) {
        } else {
          this.$message.error("查询失败");
        }
        this.loading = false;
        let data = res.data;
        // 赋值总条数
        this.totalSize = data.totalElements;
        // 赋值数组
        this.tableData = data.content;
        this.addblankmet();
        this.resetActionBar();
      });
    },
    // 单个删除
    async delSingle(row) {
      this.$confirm("此操作将永久删除该条数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        customClass: "myClass",
      })
        .then(async () => {
          let res = await API.del(row.insectPreventId);
          if (res.code === 1) {
            this.$message.success("删除成功！");
            this.getTableDataList();
          } else {
            this.$message.error("删除失败！");
          }
        })
        .catch(() => {
          //
          this.$message("取消删除");
        });
    },
    // 批量删除
    delList() {
      this.$confirm("此操作将永久删除该条数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        customClass: "myClass",
      })
        .then(async () => {
          let res = await API.delList(this.idList);
          if (res.code === 1) {
            this.$message.success("批量删除成功！");
            this.getTableDataList();
          } else {
            this.$message.error("批量删除失败！");
          }
        })
        .catch(() => {
          //
          this.$message("取消删除");
        });
    },
    handleSelectionChange(list) {
      this.delActive = true
      this.idList = []
      list.forEach(el=>{
        this.idList.push(el.insectPreventId)
      })
    },
    // 添加药品
    addMaterial() {
      this.materialNum++;
    },
    reduce(index) {
      this.materialNum--
      this.materialNos.splice(index,1)
      this.assetQuantity.splice(index,1)
      this.exchangeRatio.splice(index,1)
      this.exchangeUnitNo.splice(index,1)
    },
    // 导出
    async download() {
      let params = {
        entity: {
          ...this.entity,
        },
      };
      let url = "v3/patrol/insectAlarm/download";
      let excel = this.farmingTypeTitles + "记录表";
      this.downloadExcel(url, params, excel);
    },
    search() {
      this.currentPage = 1;
      this.getTableDataList();
    },
    changePageSize(pageSize) {
      this.pageSize = pageSize;
      this.getTableDataList();
    },
    changeCurrentPage(currentPage) {
      this.currentPage = currentPage;
      this.getTableDataList();
    },
  },
};
</script>

<style scoped lang="scss">
.facility-list {
  display: flex;
  justify-content: flex-start;
  flex-direction: row;
  flex-wrap: wrap;
  .facility-item {
    width: 400px;
    max-width: 30%;
    min-width: 30%;
    margin-right: 3%;
    margin-bottom: 10px;
    // height: 80px;
    border-radius: 5px;
    // border: 1px solid #ccc;
    box-shadow: 1px 1px 10px rgba(0, 0, 0, 0.15);
    padding: 10px 20px;

    .info-line {
      display: flex;
      justify-content: flex-start;
      align-items: flex-start;
      font-size: 14px;
      &:not(:last-child) {
        margin-bottom: 10px;
      }
      .name {
        text-align: left;
        width: 80px;
        flex-shrink: 0;
      }
      .value {
        width: 100%;
        text-align: left;
        font-weight: normal;
      }
    }
  }
}
::v-deep .el-checkbox {
  .el-checkbox__label {
    color: #dbe9e9;
    color: #d3e01c;
    // flex-direction: column;
  }
}
::v-deep .el-dialog {
  .el-dialog__header .el-dialog__title {
    color: #dbe9e9;
  }
  background-color: #005d7b;
  border: #23fff8 1px solid;
  white-space: nowrap;
  ::v-deep .el-input__inner {
    color: #dbe9e9 !important;
  }
}
::v-deep .tab-select {
  width: 100%;
  .butt-list-sty {
    position: absolute;
    left: 5px;
    top: 7px;
  }
}
td {
  ::v-deep & > div {
    width: 100% !important;
  }
}
::v-deep .el-image__error {
  display: none;
}
::v-deep .el-upload__tip {
  display: none;
}
.medicine {
  width: 100%;
 .medicine-item {
  margin-bottom: 20px;
  padding-bottom: 5px;
  border-bottom: 1px solid #ccc;
  display: flex;
  justify-content: space-between;
  .info-line1 {
    display: flex;
  }
  .info-line2 {
    display: flex;
  }
 }
}
</style>
